package com.jinlejia.bbs.logic;

import android.content.Context;

import com.jinlejia.bbs.http.utils.BBSConfig;
import com.jinlejia.bbs.http.utils.HttpCallBack;

import static com.jinlejia.bbs.http.utils.HttpUtils.JsonParse;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCall;
import static com.jinlejia.bbs.http.utils.HttpUtils.httpCallBack;
/**
 * @author 王进 on 2019/3/28.
 */
//收藏 取消收藏
public class TakeCollectionLogic {
    private Context context;
    public TakeCollectionLogic(Context context){
        this.context = context;
    }

    public void execute(String topicCode, final LogicCallBack callBack){
        String url = BBSConfig.takeCollection.concat(topicCode);
        httpCall(url).execute(httpCallBack(context, new HttpCallBack() {
            @Override
            public void onError(Exception e) {

            }

            @Override
            public void onResponse(JsonParse parse) {
                int i = parse.parse(Integer.class);
                if (i==1){
                    callBack.onResult(true);
                }else if (i==2){
                    callBack.onResult(false);
                }
            }

            @Override
            public void onNoResponse(int code) {

            }
        }));
    }

    public interface LogicCallBack{
        void onResult(boolean result);
    }
}
